<?php

/**
 * @filename source_module.php 2013-11-11 02:10:56x
 * @author Huming Xu <huming17@126.com>
 * @version 1.0.0
 * @copyright DZF (c) 2013, Huming Xu
 */
class ctrl_index_dictionary extends index_dictionary {

    public $info_array = array();
    public $page_array = array();
    public $tree_array = array();

    static function &instance() {
        static $object;
        if (empty($object)) {
            $object = new self();
        }
        return $object;
    }

    /*
     *  系统年级
    */
    function do_grade(){
        global $_G;
        //ini_set("display_errors","On");
        //error_reporting(E_ALL);
        $tmp=array("key"=>"1","value"=>"1","label"=>"一年级");
        $data[]=$tmp;
        $tmp=array("key"=>"2","value"=>"2","label"=>"二年级");
        $data[]=$tmp;
        $tmp=array("key"=>"3","value"=>"3","label"=>"三年级");
        $data[]=$tmp;
        $tmp=array("key"=>"4","value"=>"4","label"=>"四年级");
        $data[]=$tmp;
        $tmp=array("key"=>"5","value"=>"5","label"=>"五年级");
        $data[]=$tmp;
        $tmp=array("key"=>"6","value"=>"6","label"=>"六年级");
        $data[]=$tmp;
        $tmp=array("key"=>"7","value"=>"7","label"=>"初一");
        $data[]=$tmp;
        $tmp=array("key"=>"8","value"=>"8","label"=>"初二");
        $data[]=$tmp;
        $tmp=array("key"=>"9","value"=>"9","label"=>"初三");
        $data[]=$tmp;
        $tmp=array("key"=>"10","value"=>"10","label"=>"高一");
        $data[]=$tmp;
        $tmp=array("key"=>"11","value"=>"11","label"=>"高二");
        $data[]=$tmp;
        $tmp=array("key"=>"12","value"=>"12","label"=>"高三");
        $data[]=$tmp;
        $return['code'] = '0';
        $return['data'] = $data;
        echo format_data($return, $_G['gp_api'], $_G['gp_mod'], $_G['gp_action'], $_G['gp_do']);
    }
    
    /*
     *  系统学科
    */
    function do_subject(){
        global $_G;     
        $tmp=array("key"=>"1","value"=>"1","label"=>"语文");
        $data[]=$tmp;
        $tmp=array("key"=>"2","value"=>"2","label"=>"数学");
        $data[]=$tmp;
        $tmp=array("key"=>"3","value"=>"3","label"=>"英语");
        $data[]=$tmp;
        $tmp=array("key"=>"4","value"=>"4","label"=>"政治");
        $data[]=$tmp;
        $tmp=array("key"=>"5","value"=>"5","label"=>"物理");
        $data[]=$tmp;
        $tmp=array("key"=>"6","value"=>"6","label"=>"生物");
        $data[]=$tmp;
        $tmp=array("key"=>"7","value"=>"7","label"=>"地理");
        $data[]=$tmp;
        $tmp=array("key"=>"8","value"=>"8","label"=>"历史");
        $data[]=$tmp;
        $tmp=array("key"=>"9","value"=>"9","label"=>"化学");
        $data[]=$tmp;
        $tmp=array("key"=>"10","value"=>"10","label"=>"信息技术");
        $data[]=$tmp;
        $tmp=array("key"=>"11","value"=>"11","label"=>"安全知识");
        $data[]=$tmp;
        $tmp=array("key"=>"12","value"=>"12","label"=>"组合");
        $data[]=$tmp;
        $tmp=array("key"=>"13","value"=>"13","label"=>"美术");
        $data[]=$tmp;
        $tmp=array("key"=>"20244","value"=>"20244","label"=>"科学");
        $data[]=$tmp;
        $tmp=array("key"=>"20245","value"=>"20245","label"=>"社会思品");
        $data[]=$tmp;
        $tmp=array("key"=>"20246","value"=>"20246","label"=>"家庭教育");
        $data[]=$tmp;
        $tmp=array("key"=>"20247","value"=>"20247","label"=>"心理健康");
        $data[]=$tmp;
        $return['code'] = '0';
        $return['data'] = $data;
        echo format_data($return, $_G['gp_api'], $_G['gp_mod'], $_G['gp_action'], $_G['gp_do']);
    }
    
    /*
     *  系统学期
    */
    function do_term(){
        global $_G;
        $tmp=array("key"=>"1","value"=>"1","label"=>"上学期");
        $data[]=$tmp;
        $tmp=array("key"=>"2","value"=>"2","label"=>"下学期");
        $data[]=$tmp;
        $tmp=array("key"=>"3","value"=>"3","label"=>"全一年");
        $data[]=$tmp;
        $return['code'] = '0';
        $return['data'] = $data;
        echo format_data($return, $_G['gp_api'], $_G['gp_mod'], $_G['gp_action'], $_G['gp_do']);
    }
    
    /*
     *  系统难度
    */
    function do_difficult(){
        global $_G;
        $tmp=array("key"=>"1","value"=>"1","label"=>"基础课");
        $data[]=$tmp;
        $tmp=array("key"=>"2","value"=>"2","label"=>"提优课");
        $data[]=$tmp;
        $tmp=array("key"=>"3","value"=>"3","label"=>"竞赛课");
        $data[]=$tmp;
        $tmp=array("key"=>"4","value"=>"4","label"=>"衔接课");
        $data[]=$tmp;
        $return['code'] = '0';
        $return['data'] = $data;
        echo format_data($return, $_G['gp_api'], $_G['gp_mod'], $_G['gp_action'], $_G['gp_do']);
    }
    
    /*
     *  系统课程开班分类
    */
    function do_term_cate(){
        global $_G;
        $tmp=array("key"=>"1","value"=>"1","label"=>"春季班");
        $data[]=$tmp;
        $tmp=array("key"=>"2","value"=>"2","label"=>"暑假班");
        $data[]=$tmp;
        $tmp=array("key"=>"3","value"=>"3","label"=>"秋季班");
        $data[]=$tmp;
        $tmp=array("key"=>"4","value"=>"4","label"=>"寒假版");
        $data[]=$tmp;
        $return['code'] = '0';
        $return['data'] = $data;
        echo format_data($return, $_G['gp_api'], $_G['gp_mod'], $_G['gp_action'], $_G['gp_do']);
    }
    
    /*
     *  系统是否发布
    */
    function do_flag(){
        global $_G;
        $tmp=array("key"=>"0","value"=>"0","label"=>"未发布");
        $data[]=$tmp;
        $tmp=array("key"=>"1","value"=>"1","label"=>"已发布");
        $data[]=$tmp;
        $return['code'] = '0';
        $return['data'] = $data;
        echo format_data($return, $_G['gp_api'], $_G['gp_mod'], $_G['gp_action'], $_G['gp_do']);
    }
    /*
     *  期号
    */
    function do_issue(){
        global $_G;
        $tmp=array("key"=>"1","value"=>"1","label"=>"第1期");
        $data[]=$tmp;
        $tmp=array("key"=>"2","value"=>"2","label"=>"第2期");
        $data[]=$tmp;
        $tmp=array("key"=>"3","value"=>"3","label"=>"第3期");
        $data[]=$tmp;
        $tmp=array("key"=>"4","value"=>"4","label"=>"第4期");
        $data[]=$tmp;
        $tmp=array("key"=>"5","value"=>"5","label"=>"第5期");
        $data[]=$tmp;
        $tmp=array("key"=>"6","value"=>"6","label"=>"第6期");
        $data[]=$tmp;
        $return['code'] = '0';
        $return['data'] = $data;
        echo format_data($return, $_G['gp_api'], $_G['gp_mod'], $_G['gp_action'], $_G['gp_do']);
    }
    
    /*
     *  期号
    */
    function do_cm_cc_id_3_1(){
        global $_G;
        //ini_set("display_errors","On");
        //error_reporting(E_ALL);
        $api=isset($_REQUEST['api']) ? $_REQUEST['api']:'json';
        $client=isset($_REQUEST['client']) && !empty($_REQUEST['client']) ? $_REQUEST['client']:'wap';
        $page = max(1, intval($_GET['page']));
        $perpage = $limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : 200;
        $start=(($page-1) * $perpage);
        $wheresql = " AND cc_type=3 AND cc_level=1 ";
        $orderby = " ORDER BY cc_id DESC,cc_order ASC";
        //DEBUG 初始化请求请求获取一页列表数据的参数
        $page_condition=array(
            'page' => $page,//int 请求页面 页码
            'limit' => $limit,//int 每页请求个数
            'perpage' => $perpage,//int 每页显示个数
            'wheresql' => $wheresql,//string //条件SQL语句 
            'orderby' => $orderby,//string 排序规则
        );
        //DEBUG 列表数据返回结构
        /*
        $page_result = array(
            //int 返回结果总数
            'total_rows' => $total_rows,
            //array 一页数据数组
            'page_data' => $page_data 
        );
        */
        $page_result = $this->index('course_cate',$page_condition);
        //DEBUG 格式化输出
        foreach($page_result['page_data'] AS $key => $value){
           $tmp_value['key'] = $value['cc_id'];
           $tmp_value['value'] = $value['cc_id'];
           $tmp_value['p'] = $value['cc_parent_id'];
           $tmp_value['label'] = $value['cc_name'];
           $page_result['page_data'][$key]=$tmp_value;
        }
        //DEBUG 格式化树形数组
        $cc_parent_id=0;
        $page_result['page_data']=$this->arr2tree_pc($page_result['page_data'],$cc_parent_id);
        $root_node = array();
        //array_unshift($page_result['page_data'],$root_node);
        if($_G['gp_api']){
            $return['code'] = '0';
            $return['data']=$page_result['page_data'];
            $data = isset($_REQUEST['data']) ? $_REQUEST['data'] : "";
            if($data){
                echo json_ext($page_result['page_data']);die;
            }else{
                echo format_data($return,$_G['gp_api'],$_G['gp_mod'],$_G['gp_action'],$_G['gp_do']);
            }
        }
    }
}
?>